#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <aclconio.h>
#include <define.h>
#include <transact.h>
#include <tran.h>
#include <gds.h>
#include <sizes.h>
#include "ConfProto.h"
#include "tblutil.h"
#include <\SOFTPAY\Ver30\source\include\sizes.h>
#include <\SOFTPAY\Ver30\HostSrc\citisrc\citiids.h>
#include <\SOFTPAY\Ver30\HostSrc\cpacsrc\cpacids.h>
#include <confio.h>

#include <\SOFTPAY\Ver30\source\include\CST.h>



static void *storeFromStruct;

static int recordNum;
void registerCST(void *ptr)
{
	 storeFromStruct = ptr;
}

void *dealWithAddressBoundary(void*address);
int	inLoadCSTRecFromStruct (int inRecNumber, void *vdStruct)
{
	int inRet;
	char* tmp = (char*)vdStruct;

	registerCST(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	inRet = inLoadConfRec(CST_FILENAME, SIZE_CST_REC, inRecNumber, vdStruct);

	recordNum = inRecNumber;
	return inRet;
}

void vdRestoreCSTRecFromStruct(void *vdStruct)
{
	registerCST(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	memcpy((char *) pvdGetCSTRec(), vdStruct, SIZE_CST_REC);

}

void vdCopyCSTRecFromStruct(void *vdStruct)
{
	registerCST(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
		memcpy(vdStruct, (char *) pvdGetCSTRec(), SIZE_CST_REC);

}

int	inSaveCSTRecFromStruct (int inRecNumber,  void *vdStruct)
{
	int inRet;

	registerCST(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	inRet = inSaveConfRec(CST_FILENAME, SIZE_CST_REC, inRecNumber, (char *) vdStruct);

	return inRet;
}

int	inUpdateCSTRecFromStruct (void *vdStruct)
{
	int inRet;

	registerCST(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	inRet = inSaveConfRec(CST_FILENAME, SIZE_CST_REC, recordNum, (char *) vdStruct);

	return inRet;
}

short shGetCurrencyIndexFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return shGetCurrencyIndex();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((CST_REC*)vdStruct)->shCurrencyIndex;
}

void vdSetCurrencyIndexFromStruct(short shCurrencyIndex, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetCurrencyIndex(shCurrencyIndex);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((CST_REC*)vdStruct)->shCurrencyIndex = shCurrencyIndex;
}

char* szGetCurSymbolFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return szGetCurSymbol();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((CST_REC*)vdStruct)->szCurSymbol;
}

void vdSetCurSymbolFromStruct(const char* szCurSymbol, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetCurSymbol(szCurSymbol);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	strNumCopy(((CST_REC*)vdStruct)->szCurSymbol, szCurSymbol, sizeof(((CST_REC*)NULL)->szCurSymbol)-1);
}

char* szGetCurCodeFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return szGetCurCode();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((CST_REC*)vdStruct)->szCurCode;
}

void vdSetCurCodeFromStruct(const char* szCurCode, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetCurCode(szCurCode);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	strNumCopy(((CST_REC*)vdStruct)->szCurCode, szCurCode, sizeof(((CST_REC*)NULL)->szCurCode)-1);
}

